package sk.bielyvlk.vlkgps.osd;

import java.util.Iterator;
import java.util.LinkedList;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;

public class Osd {
	private LinkedList<OsdWidget> widgets = new LinkedList<OsdWidget>();
	
	public Osd() {
	}
	
	public void addWidget(OsdWidget widget) {
		widgets.add(widget);
	}
	
	public void removeWidget(OsdWidget widget) {
		widgets.remove(widget);
	}
	
	public void removeAll() {
		widgets.clear();
	}
	
	public void onDraw(Canvas canvas) {
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
		Iterator<OsdWidget> it = widgets.iterator();
		while (it.hasNext()) {
			it.next().onDraw(canvas, paint);
		}
	}
	
	public boolean onEvent(MotionEvent event) {
		Iterator<OsdWidget> it = widgets.iterator();
		while (it.hasNext()) {
			if (it.next().onEvent(event)) return true;
		}
		return false;
	}

}
